# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=tin
pkgver=2.6.3
pkgrel=0
pkgdesc="Threaded NNTP and spool-based Usenet newsreader"
url="http://www.tin.org/"
arch="all"
license="BSD-3-Clause"
depends="
	aspell
	gnupg
	"
makedepends="
	cmd:yacc
	gettext-dev
	icu-dev
	libgsasl-dev
	libidn-dev
	ncurses-dev
	openssl-dev
	pcre2-dev
	perl
	zlib-dev
	"
subpackages="$pkgname-doc $pkgname-lang $pkgname-perl::noarch"
# download from a mirror as ftp connections to ftp.tin.org are throttled
source="https://nic.funet.fi/pub/unix/news/tin/v${pkgver%.*}/tin-$pkgver.tar.xz
	default-url-handler.patch
	"

build() {
	./configure \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--enable-shell-escape \
		--enable-nntp \
		--enable-nls \
		--enable-ipv6 \
		--enable-append-pid \
		--enable-posting \
		--enable-piping \
		--enable-locale \
		--enable-xhdr-xref \
		--enable-included-msgs \
		--enable-mh-mail-handling \
		--enable-cancel-locks \
		--enable-heapsort \
		--with-pkg-config \
		--with-spooldir=/var/spool/news \
		--with-ispell="$(command -v aspell)" \
		--with-gpg="$(command -v gpg)" \
		--with-nntps=openssl \
		--with-pcre2-config \
		--with-screen=ncursesw \
		--with-sum="$(command -v sum)" \
		--with-inews-dir=/usr/bin \
		--with-libdir=/var/lib/news \
		--with-mime-default-charset=UTF-8 \
		--disable-mime-strict-charset \
		--disable-prototypes \
		--disable-echo
	make build
	make
}

check() {
	HOME="$srcdir" ./src/tin -V
}

package() {
	make DESTDIR="$pkgdir" install
	make DESTDIR="$pkgdir" install_sysdefs

	cd "$pkgdir"

	# conflict with mutt package
	rm -v usr/share/man/man5/mbox.5
	rm -v usr/share/man/man5/mmdf.5

	mv -v usr/bin/url_handler.pl usr/bin/tin_url_handler.pl
	mv -v usr/share/man/man1/url_handler.pl.1 \
		usr/share/man/man1/tin_url_handler.pl.1
}

perl() {
	pkgdesc="$pkgdesc (perl helper scripts)"
	depends="perl-io-socket-ssl"
	install_if="$pkgname=$pkgver-r$pkgrel perl"

	amove usr/bin/*.pl
}

sha512sums="
e8b474849e3330475e92b7c578ffe2f29f022303be266d39493e58b7227d9a5ee3915812c1806f52358c07f91d6119810498db906d2da7ffe035feba0e340a42  tin-2.6.3.tar.xz
8a7649effe277cd181adeb9b71983d5b1ea57094e8309f44d2bb6f33d1f57dd8bde8812969a4982a62af0d2528e618417b80a77b8f41adf8ef1f9c41816b56a3  default-url-handler.patch
"
